import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

const login = ()=> import('../views/login.vue')
const layout = ()=> import('../components/layout.vue')
const menu = ()=> import('../views/menu/index.vue')
const role = ()=> import('../views/role/index.vue')
const admin = ()=> import('../views/admin/index.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'layout',
    component: layout,
    children:[
      {
        path: 'menu',
        component: menu,
        meta:{
          title:'菜单管理'
        }
      },
      {
        path: 'role',
        component: role,
        meta:{
          title:'角色管理'
        }
      },
      {
        path: 'admin',
        component: admin,
        meta:{
          title:'管理员管理'
        }
      },
    ]
  },
  {
    path: '/login',
    component: login,
    meta:{
      title:'欢迎登陆'
    }
  },
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,  // 固定的前缀
  routes,
})
// 全局前置导航守卫
router.beforeEach((to, from, next)=>{
  document.title = to.meta.title || 'u-admin';
  next();
})

export default router
